<template>
  <div>
    <div class="blockLeft">
      <span class="aSpan">{{ptitle}}</span>
    </div>
    <div :class="pline === 1?'blockRightLong':'blockRight'">
      <span v-if="preadonly" class="aSpan">{{realValue}}</span>
      <el-date-picker
        v-else
        v-model="realValue"
        value-format="yyyy-MM-dd"
        :clearable="false"
        @change="changeAction"
        type="date"/>
    </div>
  </div>
</template>

<script>
export default {
  name: 'bpmCBlockdate',
  model: {
    prop: 'pcontent',
    event: 'changed'
  },
  props: {
    // 只读/可编辑,
    preadonly: {
      type: Boolean,
      default: false
    },
    // 可能占一整行或行的一半
    pline: {
      type: Number,
      default: 2
    },
    ptitle: {
      type: String,
      default: ' '
    },
    pcontent: {
      type: String,
      default: ' '
    },
    validateExp: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data: function () {
    return {
      realValue: this.pcontent.substr(0, 10)
    }
  },
  watch: {
    pcontent (to) {
      this.realValue = to.substr(0, 10)
    }
  },
  methods: {
    changeAction () {
      console.log('changeAction', this.realValue)
      // console.log('result?=>', this.$refs.eldate.visibleDate())
      this.$emit('changed', this.realValue + ' 00:00:00')
      this.$emit('valueChanged', this.realValue + ' 00:00:00')
    }
  },
  mounted () {
    console.log('date pcontent============', this.pcontent)
    this.realValue = this.pcontent.substr(0, 10)
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .blockLeft {
    background-color: #f4f4f4;
    float: left;
    text-align: center;
    width: 140px;
    min-height: 26px;
    border-left: 1px solid #e3e3e3;
    border-right: 1px solid #e3e3e3;
  }
  .blockRight {
    background-color: #eff3f6;
    float: left;
    padding-left: 8px;
    min-height: 26px;
    width: 340px;
    min-width: 340px;
    text-align: left;
  }
  .blockRightLong {
    background-color: #eff3f6;
    float: left;
    padding-left: 8px;
    min-height: 26px;
    width: 830px;
    min-width: 830px;
    text-align: left;
  }
  .aSpan {
    display: block;
    margin-top: 4px;
  }
</style>
